<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>
        栋数管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/statics/layui-v2.6.8//layui/css/layui.css">

    <link rel="stylesheet" href="${pageContext.request.contextPath }/statics/css/main.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/statics/css/bootstrap.css">

</head>
<style>
    #LAY_demo1 {
        overflow: auto;
        width: 600px;
        height: 400px;
    }
</style>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>房产管理</cite></a>
              <a><cite>栋数管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:800px">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
                <label class="layui-form-label">日期范围</label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="开始日" id="LAY_demorange_s" name="beginDate">
                </div>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="截止日" id="LAY_demorange_e" name="overDate">
                </div>
                <div class="layui-input-inline">
                    <select name="region" id="region">
                        <option value="0">选择所属区域</option>
                        <option value="A">A区</option>
                        <option value="B">B区</option>
                        <option value="C">C区</option>
                        <option value="D">D区</option>
                        <option value="E">E区</option>
                    </select>
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </div>
    </form>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()">
            <i class="layui-icon">&#xe640;</i>批量删除
        </button>
        <button class="layui-btn" onclick="veh_add('车辆添加','parkingPlace_add','1000','600')">
            <i class="layui-icon">&#xe608;</i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge" id="count">1</span> 条</span>
    </xblock>

    <div class="layui-progress" lay-showPercent="true">
        <div class="layui-progress-bar layui-bg-red" lay-percent="2/3"></div>
    </div>

    <div class="layui-progress layui-progress-big" lay-filter="demo" lay-showPercent="true">
        <div class="layui-progress-bar" lay-percent="10%"></div>
    </div>

    <div style="width: 500px;height: 500px;background-color: #8D8D8D">
        <table id="demo" lay-filter="test"></table>
    </div>

</div>

<%--
<script src="${pageContext.request.contextPath }/statics/lib/layui/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/statics/js/x-layui.js" charset="utf-8"></script>--%>
<%--<script src="${pageContext.request.contextPath }/statics/js/x-layui.js" charset="utf-8"></script>--%>
<script src="${pageContext.request.contextPath }/statics/layui-v2.6.8/layui/layui.js"></script>
<script>
    layui.use('table', function () {
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            , width: 455
            , height: 312
            , url: '/parkingIn/list?size=100' //数据接口
            , page: false //开启分页
            , cols: [[ //表头
                {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left'}
                , {field: 'carNumber', title: '入口车辆', width: 100}
                , {field: 'inDate', title: '进入时间', width: 110, sort: true}
                , {field: 'carType', title: '车辆类型', width: 85}
                , {field: 'parking', title: '车位', width: 64.3}
                // , {field: 'score', title: '操作', width: 80, sort: true}
            ]], parseData: function (res) {
                console.log('返回的值', res)
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }/*, request: {
                pageName: 'curr' //页码的参数名称，默认：page
                , limitName: 'nums' //每页数据量的参数名，默认：limit
            }*/
        });

    });
</script>

<script>
    layui.use('flow', function () {
        var flow = layui.flow;

        flow.load({
            elem: '#LAY_demo1' //流加载容器
            , scrollElem: '#LAY_demo1' //滚动条所在元素，一般不用填，此处只是演示需要。
            , done: function (page, next) { //执行下一页的回调

                //模拟数据插入
                setTimeout(function () {
                    var lis = [];

                    for (var i = 0; i < 80; i++) {
                        if (obj != null) {
                            lis.push('<li style="border: 1px red solid;width: 100px;height: 100px;float: left">' + ((page - 1) * 8 + i + 1) + '</li>')
                        } else {
                            lis.push('<li style="border: 1px green solid;width: 100px;height: 100px;float: left">' + ((page - 1) * 8 + i + 1) + '</li>')
                        }
                    }

                    //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                    //pages为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                    next(lis.join(''), page < 10); //假设总页数为 10
                }, 500);
            }
        });

    });
</script>
<script>
    //Js方式将Div截取生成base64格式的字符串
    function takeScreenshot(i) {
        html2canvas(document.getElementById('imgDiv'), {
            onrendered: function (canvas) {
                var imgURL = canvas.toDataURL("image/png");
                $.ajax({
                    url: "/Parking/parking/GenerateImage",
                    type: "POST",
                    dataType: "JSON",
                    data: {
                        base64: imgURL,
                        i: i
                    }
                });
            }
        });
    }

    //获取Redis中的数据动态生成
    function getCarNumber() {
        $.ajax({
            url: "/Parking/parking/getCarNumber",
            type: "POST",
            dataType: "JSON",
            success: function (data) {
                for (var k = 0; k < data.length; k++) {
                    const obj = JSON.parse(data[k]);
                    if (a[k] == obj.position) {
                        if (24 > k) {
                            $("#" + a[k]).find("img").each(function (q, ob) {
                                for (var a = 0; a < obj.carNubmer.length; a++) {
                                    if (obj.carNubmer[a].x == q) {
                                        if (k % 2 == 0) $(this).attr("src", "/Parking/statics/img/red_upper.png");
                                        else $(this).attr("src", "/Parking/statics/img/red_lower.png");
                                    }
                                }
                            })
                        } else {
                            $("#" + a[k]).find("img").each(function (q, ob) {
                                const num = obj.carNubmerSize;
                                for (var a = 0; a < obj.carNubmer.length; a++) {
                                    if (obj.carNubmer[a].x == q)
                                        $(this).attr("src", "/Parking/statics/img/red_upper.png");
                                }
                            })
                        }
                    }
                }
                takeScreenshot(0);
                for (var k = 0; k < data.length; k++) {
                    const obj = JSON.parse(data[k]);
                    $("#" + a[k] + " div").find("span").each(function (q, ob) {
                        var boo = false;
                        for (var a = 0; a < obj.carNubmer.length; a++) {
                            if (obj.carNubmer[a].x == q) {
                                $(ob).text(obj.carNubmer[a].carNubmer);
                                boo = true;
                            }
                        }
                        if (!boo) {
                            $(ob).html("空余车位  &nbsp;&nbsp;");
                        }
                    })
                }
                takeScreenshot(1);
            }
        });
    }

    getCarNumber()
    var a = new Array("A1", "A2", "A3", "A4", "B1", "B2", "B3", "B4", "C1", "C2", "C3", "C4", "D1", "D2", "D3", "D4", "E1", "E2", "E3", "E4", "F1", "F2", "F3", "F4", "G1", "G2", "G3", "G4", "G5", "G6");

    //生成所有位置信息
    function get() {
        for (var i = 0; i < 30; i++) {
            const po = a[i];
            if (24 > i) {
                $("#" + a[i]).find("img").each(function (q, ob) {
                    if (i % 2 == 0) $(this).attr("src", "/Parking/statics/img/red_upper.png");
                    else $(this).attr("src", "/Parking/statics/img/red_lower.png");
                })
                html2canvas(document.getElementById('imgDiv'), {
                    onrendered: function (canvas) {
                        var imgURL = canvas.toDataURL("image/png");
                        $.ajax({
                            url: "/Parking/parking/setImg",
                            async: false,
                            type: "POST",
                            dataType: "JSON",
                            data: {
                                base64: imgURL,
                                img: po
                            }
                        });
                    }
                });
                $("#" + a[i]).find("img").each(function (q, ob) {
                    if (i % 2 == 0) $(this).attr("src", "/Parking/statics/img/green_upper.png");
                    else $(this).attr("src", "/Parking/statics/img/green_lower.png");
                })
            } else {
                $("#" + a[i]).find("img").each(function (q, ob) {
                    $(this).attr("src", "/Parking/statics/img/red_upper.png");
                })
                html2canvas(document.getElementById('imgDiv'), {
                    onrendered: function (canvas) {
                        var imgURL = canvas.toDataURL("image/png");
                        $.ajax({
                            url: "/Parking/parking/setImg",
                            async: false,
                            type: "POST",
                            dataType: "JSON",
                            data: {
                                base64: imgURL,
                                img: po
                            }
                        });
                    }
                });
                $("#" + a[i]).find("img").each(function (q, ob) {
                    $(this).attr("src", "/Parking/statics/img/green_upper.png");
                })
            }
        }
    }

    get()
</script>
</body>
</html>